<template>
	<view class="ListBox">
		<!-- #ifdef H5 -->
		<view class="header">
			<image class="back" src="../../static/images/back_icon.png" mode="scaleToFill" lazy-load="true"></image>
		</view>
		<!-- #endif -->
		<view v-if="!empty">
			<view class="uni-list  specials" v-if="titleName == '天天特价'">
				<view class="uni-list-cell selectList" v-for="(item,index) in selectList" :key="index" @tap="goDetails(item)">
					<view class="imgbox">
						<image :src="item.pic.split(',')[0]" mode="scaleToFill" lazy-load="true"></image>
					</view>
					<view class="">
						<view class="desction">
							{{item.name}}
						</view>
						<view class="bigfactory">
							大厂直降
						</view>
						<view>
							<view class="priceBox">
								￥ <text class="price">{{item.price}} </text>  <text class="oldprice">￥{{ item.originalPrice}}</text>
							</view>
							<view class="storeName">
								{{item.storeName}}
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="uni-list selectLists" v-else>
				<view class="uni-list-cell selectList" v-for="(item,index) in selectList" :key="index" @tap="goDetails(item)">
					<view class="imgbox">
						<image :src="item.pic.split(',')[0]" mode="scaleToFill" lazy-load="true"></image>
					</view>
					<view class="desction">
						{{item.name}}
					</view>
					<view class="priceBox">
						<view class="price">
							￥{{item.price}}
						</view>
						<view class="salesNum">
							总销量{{item.sale}}
						</view>
					</view>
				</view>
			</view>
		
		</view>
		
		<view class="loadStatusText" v-if="!empty">
			{{loadStatusText}}
		</view>
		<view class="empty" v-if="empty">
			<!-- <image src="../../static/images/tixian%20.png" mode=""></image> -->
		</view>
	</view>
</template>

<script>
	export default{
		data() {
			return {
				loadStatusText:"加载中...",
				selectList:[],
				pageNum:1,
				titleId:"",
				titleName:"",
				empty:false
			}
		},
		onLoad(e) {
			uni.setNavigationBarTitle({
				title:e.name
			})
			this.titleId = e.titleId
			this.titleName = e.name
			if(e.name == '大牌抢购' || e.name == "必买清单" || e.name == "天天特价" ){
				this.getData(e.titleId)
			}else{
				this.getQuckNav(e.titleId)
			}
		},
		onReachBottom() {
			// this.getData(this.titleId)
			if(this.titleName == '大牌抢购' || this.titleName == "必买清单" || this.titleName == "天天特价" ){
				this.getData(this.titleId)
			}else{
				this.getQuckNav(this.titleId)
			}
		},
		methods:{
			getData(e){
				let data = {
					"pageNum": this.pageNum,
					"pageSize": 10,
					"status": e,
				}
				this.$http.post(this.$http.baseUrl + '/api/v1.0/app/product/findProductByStatus',data,res=>{
					this.pageNum++
					if(res.data.data.length == 0){
						if(this.selectList.length>0){
							this.loadStatusText = "已加载全部"
						}else{
							this.empty = true
						}
					}else{
						this.loadStatusText = "加载成功"
						if(this.selectList.length == 0){
							this.selectList = res.data.data;
						}else{
							this.selectList = this.selectList.concat(res.data.data);
							this.loadStatusText = "加载成功"
						}
					}
				})
			},
			getQuckNav(e){
				this.pageNum++
				let data = {
					"pageNum": this.pageNum,
					"pageSize": 10,
					"categoryId": e,
				}
				this.$http.post(this.$http.baseUrl + '/api/v1.0/app/product/getProductsByCategoryId',data,res=>{
					console.log(res)
					if(res.data.data.length == 0){
						if(this.selectList.length>0){
							this.loadStatusText = "已加载全部"
						}else{
							this.empty = true
						}
						return false;
					}else{
						this.loadStatusText = "加载成功"
						if(this.selectList.length == 0){
							this.selectList = res.data.data;
						}else{
							this.selectList = this.selectList.concat(res.data.data);
							this.loadStatusText = "加载成功"
						}
					}
				})
			},
			goDetails(e){
				uni.navigateTo({
					url:'/pages/details/details?id=' + e.id
				})
			},
		
		}
	}
</script>

<style lang="scss">
	.ListBox{
		background-color: #f2f2f2;
		// height: 100%;
		padding: 28upx;
		.header{
			text-align: center;
			// background-color: #FF484A;
			height: 130upx;
			line-height: 130upx;
			/* #ifdef H5 */
			.back{
				float: left;
				width: 22upx;
				height: 22upx;
			}
			/*#endif*/
			.title{
				width: 203upx;
				height: 48upx;
			}
			
		}
		.selectLists{
			// margin-top: 50upx;
			display: flex;
			justify-content: space-between;
			flex-wrap: wrap;
			.selectList{
				border-radius: 20upx;
				background-color: #fff;
				overflow: hidden;
				width: 334upx;
				height: 530upx;
				margin-right: 25.7upx;
				margin-bottom: 26upx;
				&:nth-child(2n){
					margin-right: 0;
				}
				image{
					width: 334.3upx;
					height: 333upx;					
				}
				.desction{
					width: 297upx;
					margin: 24upx auto;
					color: #333;
					font-weight: 500;
					font-size: 28upx;
					display: -webkit-box;
					overflow: hidden; 
					white-space: normal!important;
					text-overflow: ellipsis;
					word-wrap: break-word; 
					-webkit-line-clamp: 2;
					-webkit-box-orient: vertical;
					
				}
				.priceBox{
					display: flex;
					justify-content: space-between;
					width: 297upx;
					margin: 0 auto;
					.price{
					color: #F63810;
					font-size: 24upx;
						text{
							font-size: 32upx;
							font-weight: bold;
						}
					}
					.salesNum{
						color: #4d4d4d;
						font-size: 24upx;
					}
				}
				
			}
		}
		.specials{
			.selectList{
				display: flex;
				justify-content: flex-start;
				background-color: #fff;
				box-sizing: border-box;
				margin-bottom: 20upx;
				padding: 20upx;
				// padding-right: 0;
				.imgbox{
					margin-right: 25upx;
					image{
					width: 241upx;
					height: 241upx;
					}
				}
				.desction{
					font-size: 30upx;
					color: #333;
					display: -webkit-box;
					overflow: hidden; 
					white-space: normal!important;
					text-overflow: ellipsis;
					word-wrap: break-word; 
					-webkit-line-clamp: 2;
					-webkit-box-orient: vertical;
					
				}
				.bigfactory{
					background-color: #f63810;
					color: #fff;
					margin-top: 20upx;
					font-size: 22upx;
					width: 108upx;
					height: 36upx;
					border-radius: 17.5upx;
					text-align: center;
				}
				.priceBox{
					font-size: 24upx;
					color: #F63810;
					.price{
						font-size: 32upx;
					}
					.oldprice{
						color: #B3B3B3;
						text-decoration: line-through;
						margin-left: 10upx;
					}
				}
				.storeName{
					color: #4d4d4d;
					font-size: 22upx;
					margin-top: 10upx;
				}
			}
		}
		.loadStatusText{
			font-size: 24upx;
			text-align: center;
			color: #999999;
			height: 100upx;
			line-height: 100upx;
		}
		.empty{
			height: 100vh;
			display: flex;
			justify-content: center;
			align-items: center;
			image{
				width: 386upx;
				height: 330upx;
			}
		}
	}
	
</style>
